﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrismStudy.ViewModels
{
    class MyDialogViewViewModel : BindableBase, IDialogAware
    {
        private string title;

        public string Title
        {
            get { return title; }
            set { title = value; RaisePropertyChanged(); }
        }


        private string myVar;

        public string MyVar
        {
            get { return myVar; }
            set { myVar = value;RaisePropertyChanged(); }
        }


        public DelegateCommand SaveCommand { get; private set; }
        public DelegateCommand CancelCommand { get; private set; }

        public MyDialogViewViewModel()
        {
            
            SaveCommand = new DelegateCommand(() => {
                DialogParameters param = new DialogParameters();
                param.Add("UserInput", MyVar);
                RequestClose?.Invoke(new DialogResult(ButtonResult.OK,param));
            });

            CancelCommand = new DelegateCommand(()=> {
                RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
            });
        }


        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
            
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            Title = parameters.GetValue<string>("value");
        }
    }
}
